"""
人才画像相关路由
"""
from flask import Blueprint, render_template, jsonify, request
from app import db
from app.models import Employee, Organization
from app.services.comparison_service import ComparisonService

bp = Blueprint("talent", __name__, url_prefix="/talent")

@bp.route("/list")
def talent_list():
    """人才画像列表页面"""
    return render_template("talent/list.html")

@bp.route("/api/employees")
def get_employees():
    """获取员工列表数据"""
    employees = Employee.query.all()
    return jsonify([emp.to_dict() for emp in employees])

@bp.route("/api/organization/<int:org_id>")
def get_organization(org_id):
    """获取组织信息"""
    org = Organization.query.get_or_404(org_id)
    return jsonify(org.to_dict())

@bp.route("/compare")
def compare():
    """数据对比页面"""
    return render_template("talent/compare.html")

@bp.route("/api/compare", methods=['POST'])
def compare_data():
    """对比页面和数据库数据"""
    comparison_service = ComparisonService()
    
    # 获取所有差异
    differences = comparison_service.get_all_differences()
    
    return jsonify(differences)

@bp.route("/api/compare/organization")
def compare_organization():
    """对比组织数据"""
    comparison_service = ComparisonService()
    return jsonify(comparison_service.compare_organization_data())

@bp.route("/api/compare/employees")
def compare_employees():
    """对比员工数据"""
    comparison_service = ComparisonService()
    return jsonify(comparison_service.compare_employee_data())
